<?php
/* 
 * Photo Album Gallery (FST)
 * Abe Yang <abeyang@cal.berkeley.edu> (c) 2007
 * http://code.google.com/p/flickrsetsbytag/
 *
/* ---------------------------------------------------------------------------------- */

require('../fst.class.php');

class FSTPhotoAlbum extends FST {
	function FSTPhotoAlbum($cache_dir = FST_CACHE_DIR) {
		parent :: FST($cache_dir);
		if (FST_STANDALONE) $this->gallery = 'gallery.php';
		else $this->gallery = 'wp-gallery.php';
	} // end FSTPhotoAlbum()
	
	/* render html (view) */
	
	// options: hash array of
	//		tag, album, photo, size
	function show($options) {
		$tag = $options['tag'];
		$album = $options['album'];
		$photo = $options['photo'];
		$size = $options['size'];
		
		if (!$tag) $tag = FST_DEFAULT_TAG;
		else $tag = checkTag($tag);
		
		if ($photo) $str = $this->showPhoto($photo, $album, $tag, $size);
		else if ($album) $str = $this->showAlbum($album, $tag);
		else $str = $this->showAlbumsList($tag);
		
		return $str;
	}	// end show()
	
	function showPhoto($photoid, $albumid, $matchtag = FST_DEFAULT_TAG, $size, $info = 'showPhoto') {
		$matchtag = checkTag($matchtag);
		$album = $this->getAlbum($albumid, $matchtag, $info);
		
		$foundphoto = false;
		$i = 0;
		foreach($album['photo'] as $photo) {
			if ($photo['id'] == $photoid) {
				if ($i) {
					$prev_id = $album['photo'][$i - 1]['id'];
					$prev_str = '<div class="floatLeft">' . $this->linkToPhoto($prev_id, $albumid, $matchtag, $size, '&laquo; prev') . '</div>';
				}
				if ($i < sizeof($album['photo']) - 1) {
					$next_id = $album['photo'][$i + 1]['id'];
					$next_str = '<div class="floatRight">' . $this->linkToPhoto($next_id, $albumid, $matchtag, $size, 'next &raquo;') . '</div>';
				}
				$nav_str = '<div id="fst-nav" class="clearfix">' . $prev_str . ' ' . $next_str . '</div>';
				$str = $this->breadCrumbs($matchtag, $album['title'], $albumid, $photo['title']);
				$str .= $nav_str;
				$str .= '<h2>' . $photo['title'] . '</h2>' . "\n";
				$str .= '<div class="clearBoth">' . $this->photo($photo, $size) . "</div>\n";
				$str .= '<p>' . $photo['description'] . '</p>' . "\n";
				$str .= $nav_str;
								
				$foundphoto = true;
				break;
			}
			$i++;
		}
		
		if (!foundphoto) {
			// error log?
			$str = "Photo $photoid not found in this album!";
		}
		
		return $str;
	}	// end showPhoto()
	
	/* Views */
	
	function breadCrumbs($matchtag = FST_DEFAULT_TAG, $albumtitle = 'Album', $albumid = '', $phototitle = 'Photo') {
		$b = '<div class="fst-breadcrumbs">';
		$b .= $this->linktoAlbumsList($matchtag, $matchtag);
		if (!$albumid) $b .= ' &raquo; <strong>'. $albumtitle . '</strong>';
		else $b .= ' &raquo; ' . $this->linkToAlbum($albumid, $matchtag, $albumtitle) . ' &raquo; <strong>' . $phototitle . '</strong>';
		$b .= '</div>';
		return $b;
	}	// end breadCrumbs()
	
	// overloaded fn
	function linkToAlbumsList($matchtag = FST_DEFAULT_TAG, $content) {
		if (FST_FRIENDLY_URL)
			$o = $this->link(FST_ROOT_DIR . $matchtag, $content);
		else $o = $this->link($this->gallery . '?tag=' . $matchtag, $content);
		return $o;
	}
		
	function linkToPhoto($photoid, $albumid, $matchtag = FST_DEFAULT_TAG, $size = '', $content) {
		if (FST_FRIENDLY_URL) 
			$o = $this->link(FST_ROOT_DIR . $matchtag . '/album/' . $albumid . '/photo/' . $photoid . '/size/' . $size, $content);
		else $o = $this->link($this->gallery . '?tag=' . $matchtag . '&album=' . $albumid . '&photo=' . $photoid . '&size=' . $size, $content);
		return $o;
	}
	
} // end FSTPhotoAlbum
?>

